/**
 * 
 */
package de.szut.hh.MVC;

import java.io.PrintWriter;
import java.io.StringWriter;

import javax.swing.JLabel;

/**
 * @author hh
 * 
 */
public class CounterView extends JLabel implements PlusMinusListener {

	public static final int DECIMAL_FORMAT = 1;
	public static final int HEXADECIMAL_FORMAT = 2;
	public static final int OCTAL_FORMAT = 3;
	private int format;

	/**
	 * 
	 */
	public CounterView(PlusMinusModel model, int _format) {
		// TODO Auto-generated constructor stub
		format = _format;
		this.valueChanged(model);
	}

	public CounterView(PlusMinusModel model) {
		// anderen Konstruktor verwenden!
		this(model, DECIMAL_FORMAT);
	}

	public void valueChanged(PlusMinusModel model) {

		String s = "unbekanntes Format";
		switch (format) {
		case DECIMAL_FORMAT:
			s = model.getCounter() + " - dezimal";
			break;
		case HEXADECIMAL_FORMAT:
		case OCTAL_FORMAT:
			StringWriter sw = new StringWriter();
			PrintWriter pw = new PrintWriter(sw);
			String formatString,
			appendix;
			if (format == HEXADECIMAL_FORMAT) {
				formatString = "%x";
				appendix = " - hexadezimal";
			} else {
				formatString = "%o";
				appendix = " - octal";
			}
			
			// ???? Was soll das hier????
			pw.printf(formatString, model.getCounter());
			s = sw.toString() + appendix;

		}
		setText(s);
	}
}
